var express = require('express')
var router = express.Router()

var mysql = require('mysql')
var sql = mysql.createConnection({
	host: '182.254.187.162',
	user: 'dbuser',
	password: 'Qwer781128..',
	database: 'CJHZ'
})
sql.connect()
//获取所有路由
router.get('/getRouters', (req, res, next) => {
	sql.query('select * from user_route', [], function(err, data, aa) {
		console.log(data)
		res.send(data)
	})
})
//新增路由
router.post('/addRouters', function(req, res, next) {
	var router = req.body
	var SQL = 'INSERT INTO user_route  (route_name, route_src) VALUES (?,?)'
	var param = [router.name, router.src]
	sql.query(SQL, param, function(err, data) {
		console.log(data)
		res.send(data)
	})
})
//删除路由
router.post('/delRouters', function(req, res, next) {
	var id = req.body.id
	var SQL = 'DELETE FROM user_route where id=' + id
	sql.query(SQL, function(err, data) {
		console.log(data)
		res.send(data)
	})
})

module.exports = router
